package org.tigris.subversion.svnant;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import org.apache.tools.ant.BuildException;

public class SvnAntUtilities
{
  public static final void close(Closeable paramCloseable)
  {
    if (paramCloseable != null)
      try
      {
        paramCloseable.close();
      }
      catch (IOException localIOException)
      {
      }
  }

  public static final void attrsNotSet(String paramString, Object[] paramArrayOfObject)
  {
    attrsNotSet(paramString, false, paramArrayOfObject);
  }

  public static final void attrsNotSet(String paramString, boolean paramBoolean, Object[] paramArrayOfObject)
  {
    int i = 0;
    if (paramArrayOfObject != null)
      for (Object localObject : paramArrayOfObject)
        if ((localObject instanceof Collection))
        {
          if (((Collection)localObject).size() <= 0)
            continue;
          i++;
        }
        else
        {
          if (localObject == null)
            continue;
          i++;
        }
    if (i == 0)
      throw create("At least one value of {%s} has to be set.", new Object[] { paramString });
    if ((paramBoolean) && (i > 1))
      throw create("Only one value of {%s} is allowed to be set.", new Object[] { paramString });
  }

  public static final void attrNotNull(String paramString, Object paramObject)
  {
    if (paramObject == null)
      throw create("The attribute '%s' has not been set.", new Object[] { paramString });
  }

  public static final void attrNull(String paramString, Object paramObject)
  {
    if (paramObject != null)
      throw create("The attribute '%s' is not allowed to be set.", new Object[] { paramString });
  }

  public static final void attrIsFile(String paramString, File paramFile)
  {
    attrNotNull(paramString, paramFile);
    if (!paramFile.isFile())
      throw create("The attribute '%s' with the value '%s' is not a file.", new Object[] { paramString, paramFile });
  }

  public static final void attrExists(String paramString, File paramFile)
  {
    attrNotNull(paramString, paramFile);
    if (!paramFile.exists())
      throw create("The attribute '%s' with the value '%s' doesn't denote an existing resource.", new Object[] { paramString, paramFile });
  }

  public static final void attrIsDirectory(String paramString, File paramFile)
  {
    attrNotNull(paramString, paramFile);
    if (!paramFile.isDirectory())
      throw create("The attribute '%s' with the value '%s' is not a directory.", new Object[] { paramString, paramFile });
  }

  public static final void attrCanWrite(String paramString, File paramFile)
  {
    attrNotNull(paramString, paramFile);
    if ((paramFile.exists()) && ((paramFile.isDirectory()) || (!paramFile.canWrite())))
      throw create("The attribute '%s' which denotes the file '%s' doesn't specify a writable file.", new Object[] { paramString, paramFile });
  }

  public static final void attrNotEmpty(String paramString1, String paramString2)
  {
    attrNotNull(paramString1, paramString2);
    if (paramString2.length() == 0)
      throw create("The attribute '%s' is neither allowed to be null nor empty.", new Object[] { paramString1 });
  }

  public static final void attrInvalidValue(String paramString1, Object[] paramArrayOfObject, String paramString2)
  {
    attrNotNull(paramString1, paramString2);
    StringBuffer localStringBuffer = new StringBuffer();
    for (Object localObject : paramArrayOfObject)
    {
      if (paramString2.equals(String.valueOf(localObject)))
        return;
      if (localStringBuffer.length() > 0)
        localStringBuffer.append(", ");
      localStringBuffer.append(String.valueOf(localObject));
    }
    throw create("The attribute '%s' has the value '%s' but only the following values are allowed: {%s}.", new Object[] { paramString1, paramString2, localStringBuffer });
  }

  private static final BuildException create(String paramString, Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject == null) || (paramArrayOfObject.length == 0))
      return new BuildException(paramString);
    Object localObject = paramArrayOfObject[(paramArrayOfObject.length - 1)];
    if ((localObject instanceof Exception))
      return new BuildException(String.format(paramString, paramArrayOfObject), (Exception)localObject);
    return new BuildException(String.format(paramString, paramArrayOfObject));
  }
}

/* Location:           C:\Users\Administrator\Desktop\svnant.jar
 * Qualified Name:     org.tigris.subversion.svnant.SvnAntUtilities
 * JD-Core Version:    0.6.0
 */